package network.synchronizing;
import game.Game;

import java.util.Vector;

import network.dataFormats.NetworkPackage;
import network.dataFormats.PackageType;
import network.protocol.ServerHandler;
import physics.Body;
public class SyncDataCreator {
	public static void synchronize(Vector<NetworkPackage> packages, Game game, ServerHandler s) {
		Body b;
		for (int i = 0; i < game.engine.world.numBodies; i++) {
			b = game.engine.world.getBody(i);
			NetworkPackage p = getBodySyncPackage(b, game, s.getNextId(), game.time);
			if (p != null)
				packages.add(p);
		}
	}
	private static NetworkPackage getBodySyncPackage(Body b, Game game, int id, float time) {
		byte[] data = SyncBody.getSyncData(b, game);
		if (data == null)
			return null;
		return new NetworkPackage(PackageType.SYNCB, data, id, time);
	}
}
